package com.larry.rabbitmq.eighth;

import com.larry.rabbitmq.util.RabbitMQUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BasicProperties;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.impl.AMQBasicProperties;

/**
 * @author larry
 * @Title: larry-rabbitmq
 * @Package com.larry.rabbitmq.eighth
 * @Description: 死信队列 生产者
 * @date 7/4/212:40 PM
 */
public class Producer {

    //普通交换机名称
    public static final String NORMAL_EXCHANGE = "normal_exchange";
    //普通队列名称
    public static final String NORMAL_QUEUE = "normal_queue";

    public static void main(String args[]) throws Exception{
        Channel channel = RabbitMQUtils.getChannel();
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);


        //死信消息 设置TTL 过期时间
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();

        for (int i = 0; i < 10; i++) {
            String message = "info" + i;
            channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",properties,message.getBytes());
        }
    }
}
